package com.marquisx.tzdice;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;

public class Splash extends Activity
{
	private static final String TAG = "TZDice:splash";
	
	private View basicContainer;
	private LinearLayout backgroundImageContainer;
	private ImageView ratingSymbolIV;
	
	@Override
	public void onCreate(Bundle savedInstanceState)
	{
		super.onCreate(savedInstanceState);
		
		setContentView(R.layout.splash);
		findViews();
		prepareViews();
		setListeners();
		
		Thread splashThread = new Thread()
		{
			@Override
			public void run()
			{
				int showTime = getResources().getBoolean(R.bool.app_version_korea)? Constants.SPLASH_SHOW_TIME_KOREA : Constants.SPLASH_SHOW_TIME;
				
				try
				{
					int waited = 0;
					while (waited < showTime )
					{
						sleep(100);
						waited += 100;
					}
				}
				catch (InterruptedException e)
				{
					Log.e(TAG, "Splash screen has been interrupted:" + e.getMessage());
				}
				finally
				{
					startActivity(new Intent(Splash.this, TZDice.class));
					overridePendingTransition(R.anim.fadein, R.anim.hold);
					finish();
				}
			}
		};
		
		splashThread.start();
	}
	
	private void findViews()
	{
		basicContainer = findViewById(R.id.basic_container);
		backgroundImageContainer = (LinearLayout) findViewById(R.id.splash_image_container);
		ratingSymbolIV = (ImageView) findViewById(R.id.splash_rating_symbol);
	}
	
	private void prepareViews()
	{
		//basicContainer.setBackgroundColor(Setting.getBackgroundColor(this));
		//backgroundImageContainer.setBackgroundResource(Setting.getBackgroundPictureId(this));
		//backgroundImageContainer.getBackground().setAlpha(Constants.ALPHA_BG_PIC);
		
		setTitle(getText(R.string.app_name) + " " + getText(R.string.app_version_name));
		
		if( getResources().getBoolean(R.bool.app_version_korea))
		{
			ratingSymbolIV.setImageResource(R.drawable.korea_rating_symbol_all);
		}
		else
		{
			//ratingSymbolIV.setImageResource(R.drawable.promotion);
		}
	}
	
	private void setListeners()
	{
		
	}

}
